package com.doudoukeji.service.Activity.order.orderdetail;

import android.content.Context;
import android.util.Log;

import com.doudoukeji.service.Activity.ConstantValue;
import com.doudoukeji.service.Bean.Token;
import com.doudoukeji.service.Http.MyHttpResponseHandler;
import com.loopj.android.http.RequestParams;
import com.sanhai.android.mvp.BasePresenter;
import com.sanhai.android.service.http.BusinessClient;
import com.sanhai.android.service.http.Response;

import org.apache.http.Header;

/**
 * @version 2.0
 * @类描述：
 * @项目名称：ddgh
 * @类名称： OrderDetailsPresenter
 * @包名称： com.doudoukeji.service.Activity.order.orderdetail
 * @创建人： zhanjunjie
 * @创建时间：2016/3/15 11:19
 * @修改人：
 * @修改时间：2016/3/15 11:19
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class OrderDetailsPresenter extends BasePresenter {

    private OrderDetailsView view;

    public OrderDetailsPresenter(Context context, OrderDetailsView view) {
        super(context, view);
        this.view = view;
    }

    public void getOrderDetails(String orderId) {
        RequestParams params = new RequestParams();
        params.put("orderId", orderId);
        params.put("userId", Token.getId());
        params.put("token", Token.getToken());
        Log.d("aaaa", ConstantValue.orderdetailUrl + "?orderId=" + orderId + "&userId=" + Token.getId() + "&token=" + Token.getToken());
        BusinessClient.post(ConstantValue.orderdetailUrl, params, new MyHttpResponseHandler(view) {

            @Override
            public void onMyResponse(Response response) {
                if (response.isSucceed()) {
                    OrderDetailsBean detailsBean = new OrderDetailsBean();
                    detailsBean.setId(response.getString("id"));
                    detailsBean.setClientid(response.getString("clientId"));
                    detailsBean.setHospital(response.getString("hospital"));
                    detailsBean.setService(response.getString("service"));
                    detailsBean.setOrderDate(response.getString("orderDate"));
                    detailsBean.setDescr(response.getString("descr"));
                    detailsBean.setMoney(response.getString("money"));
                    detailsBean.setStatus(response.getString("status"));
                    detailsBean.setCreatedata(response.getString("createDate"));
                    detailsBean.setUserid(response.getString("userId"));
                    detailsBean.setPhone(response.getString("phone"));
                    detailsBean.setClientname(response.getString("clientName"));
                    view.getOrderDetaiul(detailsBean);
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                super.onFailure(i, headers, bytes, throwable);
                view.getfail();
            }
        });
    }

    public void grabSingle(String orderId) {
        RequestParams params = new RequestParams();
        params.put("orderId", orderId);
        params.put("userId", Token.getId());
        params.put("token", Token.getToken());
        BusinessClient.post(ConstantValue.grabSingle, params, new MyHttpResponseHandler() {

            @Override
            public void onMyResponse(Response response) {
                if (response.isSucceed()) {
                    view.grabSucced();
                }else{
                    view.grabFail();
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                super.onFailure(i, headers, bytes, throwable);
                view.grabFail();
            }
        });
    }
}
